package com.cloud.drore.eboss.supplier.controller;

import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.dealer.*;
import com.cloud.drore.eboos.common.util.LocalData;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.supplier.entity.po.SupplierAndDistributorRelationPo;
import com.cloud.drore.eboss.supplier.operationApiService.ISupplierAndDistributorRelationService;
import com.cloud.drore.eboss.supplier.service.IBaseDataFeign;
import com.cloud.drore.eboss.supplier.service.ICombProductFeign;
import com.cloud.drore.eboss.supplier.service.ITicketOrderFeign;
import com.cloud.drore.eboss.supplier.service.impl.SupplierCombProductOrderServiceImpl;
import com.cloud.drore.eboss.supplier.service.impl.SupplierTicketOrderServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/2/2 11:01 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@RestController
@RequestMapping("/supplierCombProductOrder")
@Api(value = "/供应商组合产品订单查询接口", description = "供应商组合产品订单查询接口-郑永涛")
public class SupplierCombProductOrderController {

    private static String ORDER_STATUS = "ORDER_STATUS";

    @Resource
    ISupplierAndDistributorRelationService supplierAndDistributorRelationService;

    @Resource
    IBaseDataFeign baseDataFeign;

    @Resource
    ICombProductFeign combProductFeign;

    @Resource
    SupplierCombProductOrderServiceImpl supplierCombProductOrderService;

    @ApiOperation(value = "组合产品订单查询")
    @PostMapping(value = "combinationProductOrder/supplierQueryCombProduct")
    public ResultMessage<List<SupplierCombProductOrderVo>> supplierQueryCombProduct(@RequestBody PagePo<OrderQueryPo> pagePo) throws BusinessException {
        // 存入当前供应商id
        pagePo.getFields().setSupplierId(LocalData.getCurrentUser().getTypeId());
        return combProductFeign.supplierQueryCombProduct(pagePo);
    }

    @ApiOperation(value = "组合产品订单详情")
    @GetMapping(value = "combinationProductOrder/getCombProductOrderDetail/{id}")
    public ResultMessage<OrderDetailVo> getCombProductOrderDetail(@PathVariable("id") Long id) throws BusinessException {
        return combProductFeign.getCombProductOrderDetail(id);
    }

    @ApiOperation(value = "组合产品订单页面加载初始化数据")
    @GetMapping(value = "/init")
    public ResultMessage<OrderInitVo> init() {
        Long supplierId = LocalData.getCurrentUser().getTypeId();
        List<SupplierAndDistributorRelationPo> supplierAndDistributorRelationPoList = supplierAndDistributorRelationService.getAllDistributorBySupplierId(supplierId).getData();
        List<MerchantVo> distributorList = supplierAndDistributorRelationPoList.stream().map(supplierAndDistributorRelationPo -> {
            MerchantVo merchantVo = new MerchantVo();
            merchantVo.setMerchantName(supplierAndDistributorRelationPo.getDistributorName());
            merchantVo.setId(supplierAndDistributorRelationPo.getId());
            return merchantVo;
        }).collect(Collectors.toList());
        OrderInitVo orderInitVo = new OrderInitVo();
        orderInitVo.setDistributorList(distributorList);
        orderInitVo.setOrderStatus(baseDataFeign.getDicListMapByCodeVo(ORDER_STATUS));
        return new ResultMessage<>(orderInitVo);
    }

}